package com.bos.data.repositories.impl;

import com.bos.data.repositories.LogRepository;
import com.bos.common.PageData;
import com.google.common.base.Strings;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Repository
@Transactional
public class LogRepositoryImpl extends BaseRepository implements LogRepository {
    public PageData findLogs(String leader, String logs, int pageSize, int pageIndex){
        StringBuffer sb = new StringBuffer();
        sb.append(" select * from  logs where 1=1 ");
        Map map=new HashMap();
        if(!Strings.isNullOrEmpty(leader)){
            sb.append(" and name=:leader ");
            map.put("leader",leader);
        }
        if(!Strings.isNullOrEmpty(logs)){
            sb.append(" and message like:logs" );
            map.put("logs","%"+logs+"%");
        }
        List order=new ArrayList();
        order.add("update_time");
        return this.getPage(sb.toString(),map,pageSize,pageIndex,order,true);
    }
}
